#!/bin/sh
# Copyright (c) 2011, bkil.hu
# This program is free software and can be distributed under the terms of
# the GNU General Public License v2,
# see COPYING for detailed licensing terms.

 printf 'mozilla backup '
 TIME=`date '+%Y-%m-%d'`
 SRC=`ls -d $HOME/.mozilla/firefox/_*.default |
      head -n1`
 #note: I have *.default linked to _* and /tmp for speed
 DST=$HOME/w/session
 NAME=sessionstore.js
 gzip -9 < $SRC/$NAME > $DST/$NAME.$TIME.gz && echo created || echo failed
exit 0

DATEREGEX="[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]"
BASE="$DST/$NAME\."
SUF="\.gz"
ls $DST/$NAME.*.gz |
grep "^$PRE.*$SUF$" |
while read R
do
 DATE=`echo "$R" | sed "s~^$BASE\($DATEREGEX\)T\($TIMEREGEX\)$~\1-2~" |
